﻿/**  PACS v1.0
* JC_Diagnosis.cs
*
* 类 名： JC_Diagnosis
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/6/5 15:24:28   douwd    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Pacs.DAL
{
	/// <summary>
	/// 数据访问类:JC_Diagnosis
	/// </summary>
	public partial class JC_Diagnosis
	{
		public JC_Diagnosis()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Pacs.Model.JC_Diagnosis model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ID != null)
			{
				strSql1.Append("ID,");
				strSql2.Append("'"+model.ID+"',");
			}
			if (model.SCODE != null)
			{
				strSql1.Append("SCODE,");
				strSql2.Append("'"+model.SCODE+"',");
			}
			if (model.SNAME != null)
			{
				strSql1.Append("SNAME,");
				strSql2.Append("'"+model.SNAME+"',");
			}
			if (model.Shelp != null)
			{
				strSql1.Append("Shelp,");
				strSql2.Append("'"+model.Shelp+"',");
			}
			if (model.SCUSTOMIZENAME1 != null)
			{
				strSql1.Append("SCUSTOMIZENAME1,");
				strSql2.Append("'"+model.SCUSTOMIZENAME1+"',");
			}
			if (model.SCUSTOMIZENAME2 != null)
			{
				strSql1.Append("SCUSTOMIZENAME2,");
				strSql2.Append("'"+model.SCUSTOMIZENAME2+"',");
			}
			if (model.SCUSTOMIZENAME3 != null)
			{
				strSql1.Append("SCUSTOMIZENAME3,");
				strSql2.Append("'"+model.SCUSTOMIZENAME3+"',");
			}
			if (model.STYPENAME != null)
			{
				strSql1.Append("STYPENAME,");
				strSql2.Append("'"+model.STYPENAME+"',");
			}
			if (model.SMEMO1 != null)
			{
				strSql1.Append("SMEMO1,");
				strSql2.Append("'"+model.SMEMO1+"',");
			}
			if (model.SMEMO2 != null)
			{
				strSql1.Append("SMEMO2,");
				strSql2.Append("'"+model.SMEMO2+"',");
			}
			if (model.SMEMO3 != null)
			{
				strSql1.Append("SMEMO3,");
				strSql2.Append("'"+model.SMEMO3+"',");
			}
			if (model.SMEMO4 != null)
			{
				strSql1.Append("SMEMO4,");
				strSql2.Append("'"+model.SMEMO4+"',");
			}
			if (model.SMEMO5 != null)
			{
				strSql1.Append("SMEMO5,");
				strSql2.Append("'"+model.SMEMO5+"',");
			}
			if (model.IFLAG != null)
			{
				strSql1.Append("IFLAG,");
				strSql2.Append("'"+model.IFLAG+"',");
			}
			if (model.SCREATEORGNAME != null)
			{
				strSql1.Append("SCREATEORGNAME,");
				strSql2.Append("'"+model.SCREATEORGNAME+"',");
			}
			if (model.DCREATEDATE != null)
			{
				strSql1.Append("DCREATEDATE,");
				strSql2.Append("'"+model.DCREATEDATE+"',");
			}
			if (model.SUPDATEORGNAME != null)
			{
				strSql1.Append("SUPDATEORGNAME,");
				strSql2.Append("'"+model.SUPDATEORGNAME+"',");
			}
			if (model.DUPDATEDATE != null)
			{
				strSql1.Append("DUPDATEDATE,");
				strSql2.Append("'"+model.DUPDATEDATE+"',");
			}
			if (model.sZXXMBM != null)
			{
				strSql1.Append("sZXXMBM,");
				strSql2.Append("'"+model.sZXXMBM+"',");
			}
			if (model.sZXXMMC != null)
			{
				strSql1.Append("sZXXMMC,");
				strSql2.Append("'"+model.sZXXMMC+"',");
			}
			if (model.ItemTypeID != null)
			{
				strSql1.Append("ItemTypeID,");
				strSql2.Append("'"+model.ItemTypeID+"',");
			}
			if (model.SCOMMONNAME != null)
			{
				strSql1.Append("SCOMMONNAME,");
				strSql2.Append("'"+model.SCOMMONNAME+"',");
			}
			strSql.Append("insert into JC_Diagnosis(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Pacs.Model.JC_Diagnosis model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JC_Diagnosis set ");
			if (model.ID != null)
			{
				strSql.Append("ID='"+model.ID+"',");
			}
			if (model.SCODE != null)
			{
				strSql.Append("SCODE='"+model.SCODE+"',");
			}
			else
			{
				strSql.Append("SCODE= null ,");
			}
			if (model.SNAME != null)
			{
				strSql.Append("SNAME='"+model.SNAME+"',");
			}
			else
			{
				strSql.Append("SNAME= null ,");
			}
			if (model.Shelp != null)
			{
				strSql.Append("Shelp='"+model.Shelp+"',");
			}
			else
			{
				strSql.Append("Shelp= null ,");
			}
			if (model.SCUSTOMIZENAME1 != null)
			{
				strSql.Append("SCUSTOMIZENAME1='"+model.SCUSTOMIZENAME1+"',");
			}
			else
			{
				strSql.Append("SCUSTOMIZENAME1= null ,");
			}
			if (model.SCUSTOMIZENAME2 != null)
			{
				strSql.Append("SCUSTOMIZENAME2='"+model.SCUSTOMIZENAME2+"',");
			}
			else
			{
				strSql.Append("SCUSTOMIZENAME2= null ,");
			}
			if (model.SCUSTOMIZENAME3 != null)
			{
				strSql.Append("SCUSTOMIZENAME3='"+model.SCUSTOMIZENAME3+"',");
			}
			else
			{
				strSql.Append("SCUSTOMIZENAME3= null ,");
			}
			if (model.STYPENAME != null)
			{
				strSql.Append("STYPENAME='"+model.STYPENAME+"',");
			}
			else
			{
				strSql.Append("STYPENAME= null ,");
			}
			if (model.SMEMO1 != null)
			{
				strSql.Append("SMEMO1='"+model.SMEMO1+"',");
			}
			else
			{
				strSql.Append("SMEMO1= null ,");
			}
			if (model.SMEMO2 != null)
			{
				strSql.Append("SMEMO2='"+model.SMEMO2+"',");
			}
			else
			{
				strSql.Append("SMEMO2= null ,");
			}
			if (model.SMEMO3 != null)
			{
				strSql.Append("SMEMO3='"+model.SMEMO3+"',");
			}
			else
			{
				strSql.Append("SMEMO3= null ,");
			}
			if (model.SMEMO4 != null)
			{
				strSql.Append("SMEMO4='"+model.SMEMO4+"',");
			}
			else
			{
				strSql.Append("SMEMO4= null ,");
			}
			if (model.SMEMO5 != null)
			{
				strSql.Append("SMEMO5='"+model.SMEMO5+"',");
			}
			else
			{
				strSql.Append("SMEMO5= null ,");
			}
			if (model.IFLAG != null)
			{
				strSql.Append("IFLAG='"+model.IFLAG+"',");
			}
			else
			{
				strSql.Append("IFLAG= null ,");
			}
			if (model.SCREATEORGNAME != null)
			{
				strSql.Append("SCREATEORGNAME='"+model.SCREATEORGNAME+"',");
			}
			else
			{
				strSql.Append("SCREATEORGNAME= null ,");
			}
			if (model.DCREATEDATE != null)
			{
				strSql.Append("DCREATEDATE='"+model.DCREATEDATE+"',");
			}
			else
			{
				strSql.Append("DCREATEDATE= null ,");
			}
			if (model.SUPDATEORGNAME != null)
			{
				strSql.Append("SUPDATEORGNAME='"+model.SUPDATEORGNAME+"',");
			}
			else
			{
				strSql.Append("SUPDATEORGNAME= null ,");
			}
			if (model.DUPDATEDATE != null)
			{
				strSql.Append("DUPDATEDATE='"+model.DUPDATEDATE+"',");
			}
			else
			{
				strSql.Append("DUPDATEDATE= null ,");
			}
			if (model.sZXXMBM != null)
			{
				strSql.Append("sZXXMBM='"+model.sZXXMBM+"',");
			}
			else
			{
				strSql.Append("sZXXMBM= null ,");
			}
			if (model.sZXXMMC != null)
			{
				strSql.Append("sZXXMMC='"+model.sZXXMMC+"',");
			}
			else
			{
				strSql.Append("sZXXMMC= null ,");
			}
			if (model.ItemTypeID != null)
			{
				strSql.Append("ItemTypeID='"+model.ItemTypeID+"',");
			}
			else
			{
				strSql.Append("ItemTypeID= null ,");
			}
			if (model.SCOMMONNAME != null)
			{
				strSql.Append("SCOMMONNAME='"+model.SCOMMONNAME+"',");
			}
			else
			{
				strSql.Append("SCOMMONNAME= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_Diagnosis ");
			strSql.Append(" where " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_Diagnosis GetModel()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ID,SCODE,SNAME,Shelp,SCUSTOMIZENAME1,SCUSTOMIZENAME2,SCUSTOMIZENAME3,STYPENAME,SMEMO1,SMEMO2,SMEMO3,SMEMO4,SMEMO5,IFLAG,SCREATEORGNAME,DCREATEDATE,SUPDATEORGNAME,DUPDATEDATE,sZXXMBM,sZXXMMC,ItemTypeID,SCOMMONNAME ");
			strSql.Append(" from JC_Diagnosis ");
			strSql.Append(" where " );
			Pacs.Model.JC_Diagnosis model=new Pacs.Model.JC_Diagnosis();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_Diagnosis DataRowToModel(DataRow row)
		{
			Pacs.Model.JC_Diagnosis model=new Pacs.Model.JC_Diagnosis();
			if (row != null)
			{
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["SCODE"]!=null)
				{
					model.SCODE=row["SCODE"].ToString();
				}
				if(row["SNAME"]!=null)
				{
					model.SNAME=row["SNAME"].ToString();
				}
				if(row["Shelp"]!=null)
				{
					model.Shelp=row["Shelp"].ToString();
				}
				if(row["SCUSTOMIZENAME1"]!=null)
				{
					model.SCUSTOMIZENAME1=row["SCUSTOMIZENAME1"].ToString();
				}
				if(row["SCUSTOMIZENAME2"]!=null)
				{
					model.SCUSTOMIZENAME2=row["SCUSTOMIZENAME2"].ToString();
				}
				if(row["SCUSTOMIZENAME3"]!=null)
				{
					model.SCUSTOMIZENAME3=row["SCUSTOMIZENAME3"].ToString();
				}
				if(row["STYPENAME"]!=null)
				{
					model.STYPENAME=row["STYPENAME"].ToString();
				}
				if(row["SMEMO1"]!=null)
				{
					model.SMEMO1=row["SMEMO1"].ToString();
				}
				if(row["SMEMO2"]!=null)
				{
					model.SMEMO2=row["SMEMO2"].ToString();
				}
				if(row["SMEMO3"]!=null)
				{
					model.SMEMO3=row["SMEMO3"].ToString();
				}
				if(row["SMEMO4"]!=null)
				{
					model.SMEMO4=row["SMEMO4"].ToString();
				}
				if(row["SMEMO5"]!=null)
				{
					model.SMEMO5=row["SMEMO5"].ToString();
				}
				if(row["IFLAG"]!=null)
				{
					model.IFLAG=row["IFLAG"].ToString();
				}
				if(row["SCREATEORGNAME"]!=null)
				{
					model.SCREATEORGNAME=row["SCREATEORGNAME"].ToString();
				}
				if(row["DCREATEDATE"]!=null && row["DCREATEDATE"].ToString()!="")
				{
					model.DCREATEDATE=DateTime.Parse(row["DCREATEDATE"].ToString());
				}
				if(row["SUPDATEORGNAME"]!=null)
				{
					model.SUPDATEORGNAME=row["SUPDATEORGNAME"].ToString();
				}
				if(row["DUPDATEDATE"]!=null && row["DUPDATEDATE"].ToString()!="")
				{
					model.DUPDATEDATE=DateTime.Parse(row["DUPDATEDATE"].ToString());
				}
				if(row["sZXXMBM"]!=null)
				{
					model.sZXXMBM=row["sZXXMBM"].ToString();
				}
				if(row["sZXXMMC"]!=null)
				{
					model.sZXXMMC=row["sZXXMMC"].ToString();
				}
				if(row["ItemTypeID"]!=null)
				{
					model.ItemTypeID=row["ItemTypeID"].ToString();
				}
				if(row["SCOMMONNAME"]!=null)
				{
					model.SCOMMONNAME=row["SCOMMONNAME"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,SCODE,SNAME,Shelp,SCUSTOMIZENAME1,SCUSTOMIZENAME2,SCUSTOMIZENAME3,STYPENAME,SMEMO1,SMEMO2,SMEMO3,SMEMO4,SMEMO5,IFLAG,SCREATEORGNAME,DCREATEDATE,SUPDATEORGNAME,DUPDATEDATE,sZXXMBM,sZXXMMC,ItemTypeID,SCOMMONNAME ");
			strSql.Append(" FROM JC_Diagnosis ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,SCODE,SNAME,Shelp,SCUSTOMIZENAME1,SCUSTOMIZENAME2,SCUSTOMIZENAME3,STYPENAME,SMEMO1,SMEMO2,SMEMO3,SMEMO4,SMEMO5,IFLAG,SCREATEORGNAME,DCREATEDATE,SUPDATEORGNAME,DUPDATEDATE,sZXXMBM,sZXXMMC,ItemTypeID,SCOMMONNAME ");
			strSql.Append(" FROM JC_Diagnosis ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JC_Diagnosis ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from JC_Diagnosis T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

